const { DataTypes, Model } = require('sequelize')
const sequelize = require('../config/database')

class Comment extends Model { }
Comment.init({
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true
  },
  article_id: {
    type: DataTypes.BIGINT,
    allowNull: false
  },
  user_id: {
    type: DataTypes.BIGINT,
    allowNull: false
  },
  content: {
    type: DataTypes.STRING(1000),
    allowNull: false
  },
  parent_comment_id: {
    type: DataTypes.BIGINT,
    allowNull: true
  },
  top_comment_id: {
    type: DataTypes.BIGINT,
    allowNull: true
  },
  del: {
    type: DataTypes.TINYINT,
    allowNull: false,
    defaultValue: 0
  },
  ctime: {
    comment: "创建时间",
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: () => new Date().getTime()
  },
  mtime: {
    comment: '更新时间',
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: () => new Date().getTime()
  },
}, {
  sequelize,
  modelName: 'Comment'
})

module.exports = Comment;